/**
 * Project  : monkey
 * Author   : Wu Tian Qiang
 * Date     : 2016/10/18 20:49:30
 */
Ext.define('Monkey.view.user.User', {
    extend: 'Ext.panel.Panel',

    id: 'mk-user',
    cls: 'mk-user',
    controller: 'ctrl-user',
    layout: 'border',
    border: false,
    initComponent: function () {
        var userStore = Ext.create('Monkey.store.user.User');
        var orgStore = Ext.create('Monkey.store.BaseTreeStore', {
            nodeParam: 'parentId',
            defaultRootId: '1',
            root: {
                expanded: true
            },
            fields: [
                {name: 'id', type: 'int'},
                {name: 'parentId', type: 'int'},
                {name: 'leaf', type: 'boolean'},
                {name: 'name', type: 'string'},
                {name: 'icon', type: 'string'},
                {name: 'expanded', type: 'boolean', mapping: 'expand'}
            ],
            proxy: {
                type: 'ajax',
                url: Monkey.URL.SERVER_URL + "/m/children_organizations.json",
                extraParams: {
                    fields: 'id,leaf,name,parentId,icon,expand'
                },
                reader: 'json'
            }
        });
        this.items = [{
            region: 'west',
            cls: 'org-tree',
            bodyStyle: 'border-width:1px 0 1px 1px',
            width: 230,
            title: '组织架构',
            icon: 'resources/icons/16/chart_organisation.png',
            xtype: 'treepanel',
            rootVisible: false,
            displayField: 'name',
            store: orgStore,
            tools: [{
                type: 'refresh',
                tooltip: '刷新',
                callback: function (treepanel) {
                    treepanel.getStore().reload();
                }
            }],
            listeners: {
                'itemclick': 'findUserByOrg'
            }
        }, {
            region: 'center',
            id: 'userGrid',
            xtype: 'grid',
            reference: 'userGrid',
            selType: 'checkboxmodel',
            store: userStore,
            listeners: {
                rowdblclick: 'rowdblclick'
            },
            tbar: [{
                icon: 'resources/icons/16/user_add.png',
                permission: 'system:user:create',
                text: '新增',
                handler: 'addUser'
            }, {
                icon: 'resources/icons/16/user_edit.png',
                permission: 'system:user:update',
                text: '修改',
                handler: 'modifyUser'
            }, '-', {
                icon: 'resources/icons/16/key_go.png',
                text: '重置密码',
                handler: 'restPasswd'
            }, {
                icon: 'resources/icons/16/outline.png',
                text: '更多操作',
                menu: [{
                    text: '封锁用户',
                    icon: 'resources/icons/16/lock.png',
                    handler: 'lockUser'
                }, {
                    text: '解封用户',
                    icon: 'resources/icons/16/lock_open.png',
                    handler: 'unlockUser'
                }, '-', {
                    text: '查看状态改变记录',
                    icon: 'resources/icons/16/note_edit.png',
                    handler: 'viewStatusHistory'
                }, '-', {
                    icon: 'resources/icons/16/eye.png',
                    text: '查看已分配的权限',
                    handler: 'viewPermission'
                }]
            }/*, '-', {
             icon: 'resources/icons/16/user_delete.png',
             text: '删除',
             handler: 'removeUser'
             }*/, '->', {
                xtype: 'textfield',
                reference: 'account',
                emptyText: '输入要查询登录帐号...'
            }, {
                xtype: 'textfield',
                reference: 'email',
                emptyText: '输入要查询邮箱...'
            }, {
                xtype: 'textfield',
                reference: 'mobile',
                emptyText: '输入要查询移动电话...'
            }, {
                iconCls: 'page-find',
                text: '查询',
                handler: 'findUser'
            }, {
                iconCls: 'refresh',
                text: '重置',
                handler: 'reloadUser'
            }],
            bbar: {
                xtype: 'pagingtoolbar',
                pageSize: 10,
                store: userStore,
                displayInfo: true,
                plugins: new Ext.ux.ProgressBarPager()
            },
            columns: [{
                width: 30,
                xtype: 'rownumberer'
            }, {
                text: 'id',
                dataIndex: 'id',
                hidden: true,
                width: 100
            }, {
                text: '&nbsp;',
                width: 80,
                xtype: 'widgetcolumn',
                widget: {
                    xtype: 'button',
                    icon: 'resources/icons/16/tag_blue.png',
                    text: '授权',
                    handler: 'showGrantWin'
                }
            }, {
                text: '登录帐号',
                dataIndex: 'account',
                flex: 1
            }, {
                text: '昵称',
                dataIndex: 'nick',
                width: 100
            }, {
                text: '性别',
                dataIndex: 'sex',
                width: 60,
                renderer: 'renderSex'
            }, {
                text: '邮箱',
                dataIndex: 'email',
                width: 150
            }, {
                text: '移动电话',
                dataIndex: 'mobile',
                width: 120
            }, {
                text: '状态',
                dataIndex: 'status',
                width: 100,
                renderer: 'renderStatus'
            }, {
                text: '组织id',
                dataIndex: 'orgId',
                hidden: true,
                width: 150
            }, {
                text: '组织',
                dataIndex: 'orgName',
                width: 120
            }]
        }];
        this.callParent();
    }
});